package rpc_netty.interfaces;

import rpc_netty.Serializer.HessianSerializer;
import rpc_netty.Serializer.JsonSerializer;
import rpc_netty.Serializer.KryoSerializer;

import javax.sql.rowset.serial.SerialException;
import java.io.IOException;

public interface CommonSerializer {
    byte[] serialize(Object object);

    Object deserialize(byte[] bytes,Class<?> clazz) throws IOException, SerialException;

    int getCode();

    static CommonSerializer getByCode(int code){
        switch (code){
            case 0:
                return new JsonSerializer();
            case 1:
                return new KryoSerializer();
            case 2:
                return new HessianSerializer();
            default:
                return null;
        }
    }
}
